package infos

import (
	"github.com/gin-gonic/gin"
	"github.com/pkg/errors"
	"gogs.xiaoyuanjijiehao.com/antlinker/antcms/core/common"
)

// 分页获取信息列表
func (c infoCtrl) getSchPageList(ctx *gin.Context) {

	page := c.GetPageInfo(ctx, common.PageModeID)
	dctx := c.DDDContext(ctx)
	sch := c.parseInfoSearch(ctx)
	pr, cs, err := c.iar.QueryPage(dctx, sch, page)
	if err != nil {
		c.ErrServerError(ctx, 1, "查找信息列表失败", errors.Wrap(err, "查找信息列表失败"))
		return
	}
	var respInfos []interface{}
	for _, v := range cs {
		col, err1 := c.car.GetColumn(dctx, v.ColumnID)
		if err1 != nil {
			c.ErrServerError(ctx, 33, "查询信息所在栏目信息失败", errors.Wrapf(err, "查询信息(%v)所在栏目信息失败.", v.InfoID))
			err = err1
			return
		}
		respInfos = append(respInfos, adapterC2RespForCode(ctx, showModeSearch, &v, col))
	}
	c.SuccessPage(ctx, page, pr, respInfos)
}
